//package com.smsc.other.kafka;
//
//import cn.hutool.core.util.IdUtil;
//import cn.hutool.json.JSONUtil;
//import com.smsc.headend.common.utils.ProtoBufferUtil;
//import com.smsc.headend.module.protocol.cosem.util.ByteUtils;
//import com.smsc.headend.module.task.consts.TaskKafkaTopic;
//import com.smsc.headend.module.task.dto.ConnectorTask;
//import com.smsc.headend.module.task.dto.ConnectorTaskResult;
//import com.smsc.headend.module.task.proto.ConnectorTaskProto;
//import com.smsc.headend.task.engine.TaskEngineApplication;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.curator.framework.CuratorFramework;
//import org.apache.kafka.clients.admin.*;
//import org.apache.zookeeper.KeeperException;
//import org.assertj.core.util.Lists;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.kafka.core.KafkaTemplate;
//import org.springframework.test.context.ActiveProfiles;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import java.util.*;
//import java.util.concurrent.ExecutionException;
//
//
//@SpringBootTest(classes = {TaskEngineApplication.class}, properties = {"UDIS_CONFIG_CENTER=http://192.168.252.55:8091"})
//@RunWith(SpringRunner.class)
////@EnableBinding(TaskKafkaTopic.class)
//@ActiveProfiles("test")
//@Slf4j
//public class KafkaSend {
//
//    @Autowired
//    AdminClient adminClient;
//
//    @Autowired
//    CuratorFramework curatorFramework;
//
//    @Autowired
//    KafkaTemplate kafkaTemplate;
//
////    @Resource(name = TaskKafkaTopic.TASK_RESULT_BACK)
////    private MessageChannel sendDemoMessageChannel;
////
////
////    @Resource(name = TaskKafkaTopic.TASK_SEND_TO_UTE)
////    private MessageChannel output;
//
//    @Test
//    public void zookeeperNode() throws InterruptedException, KeeperException {
//        boolean f = curatorFramework == null;
//
//        Thread.sleep(5000);
////        List<String> strings = client.getServices();
//
//        System.out.printf("", "sopad");
//    }
//
//
//    @Test
//    public void sendTaskEmit() {
//        String taskNo = IdUtil.randomUUID();
//        String atomicTaskNo = IdUtil.randomUUID();
//
//        byte[] res = getSendByte(taskNo, atomicTaskNo, 15544l);
//        byte[] res2 = getSendByte(taskNo, atomicTaskNo, 15545l);
//        byte[] res4 = getSendByte(taskNo, atomicTaskNo, 15545l);
//        byte[] res3 = getSendByte(taskNo, atomicTaskNo, 15545l);
//        kafkaTemplate.send(TaskKafkaTopic.TASK_SEND_TO_CON, res);
//        kafkaTemplate.send(TaskKafkaTopic.TASK_SEND_TO_CON, res2);
//        kafkaTemplate.send(TaskKafkaTopic.TASK_SEND_TO_CON, res3);
//        kafkaTemplate.send(TaskKafkaTopic.TASK_SEND_TO_CON, res4);
//        kafkaTemplate.send(TaskKafkaTopic.TASK_SEND_TO_CON, res4);
//        kafkaTemplate.send(TaskKafkaTopic.TASK_SEND_TO_CON, res4);
//        kafkaTemplate.send(TaskKafkaTopic.TASK_SEND_TO_CON, res4);
//    }
//
//    public byte[] getSendByte(String taskNo, String atomicTaskNo, long meterId) {
//        ConnectorTask taskObject = new ConnectorTask();
//        taskObject.setAtomicTaskNo(taskNo);
//        taskObject.setTaskNo(atomicTaskNo);
//        taskObject.setTerminalId(15542l);
////        taskObject.setMeterId(meterId);
//        byte[] hexByte = ByteUtils.hexStringToByte(" 00 01 00 01 00 01 00 40 C0 01 44 00 01 01 00 62 01 01 FF 02 01 02 01 01 02 05 0A 08 32 30 37 35 34 32 30 37 09 06 01 00 63 01 00 FF 19 07 E5 05 1D 06 05 01 00 00 80 00 00 19 07 E5 05 1D 06 06 1E 08 00 80 00 00 01 00 ");
//        byte[][] bytes = new byte[][]{
//                hexByte
//        };
//        taskObject.setPacketBytes(bytes);
//        taskObject.setRoleId(1);
//        taskObject.setReturnPacket(false);
//        log.info(JSONUtil.toJsonStr(taskObject));
//        ConnectorTaskProto.ConnectorTask proto = ProtoBufferUtil.toProtoBuffer(taskObject, ConnectorTaskProto.ConnectorTask.class);
//        byte[] res = proto.toByteArray();
//        return res;
//    }
//
//    @Test
//    public void getAllTopic() throws Exception {
////        ListTopicsResult listTopics = adminClient.listTopics();
////        Set<String> topics = listTopics.names().get();
////        for (String topic : topics) {
////            System.err.println(topic);
////        }
//        DescribeTopicsResult result = adminClient.describeTopics(Lists.newArrayList(
//                TaskKafkaTopic.TASK_SEND_TO_UTE,
//                TaskKafkaTopic.TASK_RESULT_BACK,
//                TaskKafkaTopic.DEVICE_READ_TRANSFER
//        ));
//
//
//        result.values().forEach((s, topicDescriptionKafkaFuture) -> {
//            try {
//                TopicDescription topicDescription = topicDescriptionKafkaFuture.get();
//                topicDescription.partitions().stream().forEach(topicPartitionInfo -> {
//                    System.out.println(topicPartitionInfo.toString());
//                });
//            } catch (InterruptedException e) {
//                Thread.currentThread().interrupt();
//            } catch (ExecutionException e) {
//                System.out.println(s);
//                NewTopic t = new NewTopic(s, 1, (short) 1);
//                adminClient.createTopics(Lists.newArrayList(t));
//            }
//
//        });
//
//    }
//
//    @Test//自定义手动创建topic和分区
//    public void testCreateTopic() throws InterruptedException {
//        // 这种是手动创建 //10个分区，一个副本
//        // 分区多的好处是能快速的处理并发量，但是也要根据机器的配置
////        NewTopic topic = new NewTopic(TaskKafkaTopic.TASK_SEND_TO_CON, 10, (short) 1);
////        adminClient.createTopics(Arrays.asList(topic));
//        adminClient.createPartitions(new HashMap<String, NewPartitions>() {{
//            put(TaskKafkaTopic.TASK_SEND_TO_CON, NewPartitions.increaseTo(10));
//        }});
//        Thread.sleep(1000);
//    }
//
//
//    @Test
//    public void send() {
//        ConnectorTaskResult result = new ConnectorTaskResult();
//        result.setExecuteCode(0);
//        result.setAtomicTaskNo("003e2c61-9395-4233-98cb-58bbb5fe31a8");
//
//        String rawDataString = "0001000100100069C401C10001060203090C07DE02120216000000FFC400112006000000000203090C07DE02120200000000FFC40011000600000000020300112006000000000203090C07DE02120204000000FFC400110006000000000203001120060000000002030011800600000000";
//        byte[] rawData = new byte[rawDataString.length() / 2];
//        for (int i = 0; i < rawDataString.length(); i = i + 2) {
//            String oneByte = rawDataString.substring(i, i + 2);
//            rawData[i / 2] = (byte) Integer.parseInt(oneByte, 16);
//        }
////
////        result.setResultByte(rawData);
////        boolean isSendSuccess = sendDemoMessageChannel.
////                send(MessageBuilder.withPayload(JSONUtil.toJsonStr(result)).build());
////        System.out.println(isSendSuccess);
//    }
//
//
//}
